package efi.easycooking.fre;

import java.util.Random;

import utils.Utils;
import efi.easycooking.ImageAdapter;
import efi.easycooking.R;

import efi.easycooking.bo.BaseResponse;
import efi.easycooking.rest.ApiService;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;

public class FreMainActivity extends Activity {

	private static String TAG = "FreMainActivity";
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fre_main);

		
		ImageButton ibSalir=(ImageButton)findViewById(R.id.ibReturnAE1);
		ibSalir.setBackgroundDrawable(null);
		ibSalir.setOnClickListener(new View.OnClickListener() {
		    public void onClick(View v) {
		    	finish();
		    	
		    }
		});
		
		
		GridView gv = (GridView) findViewById(R.id.gridView);		
		// this.RegistrarDevice();
		// ejemploDeLlamadaAlAPI();
				
		gv.setAdapter(new FreImageAdapter(this));
		gv.setOnItemClickListener(new OnItemClickListener() 
		{
			@Override
			public void onItemClick(AdapterView<?> parentView, View iv,int position, long id) 
			{
				Intent i;
				
				Bundle bundle; 
				
				switch (position) 
				{
					case 0:
						i = new Intent(getApplicationContext(), FreRecetasActivity.class);
						
						Log.d(TAG, "[onItemClick]Comenzando FreRecetasActivity Inicio");

						 bundle = new Bundle();
						  bundle.putInt("page", 1);
						  i.putExtras(bundle);
						  
						startActivity(i);
						
						break;
	
					case 1:
													
						i = new Intent(getApplicationContext(), FreRecetasActivity.class);
						Log.d(TAG, "[onItemClick] Comenzando FreRecetasActivity Ramdon");
						
						Random rd=new Random();
																		    
						  bundle = new Bundle();

						  //bundle.putInt("page", rd.nextInt(RecetasEsp.3));
						  int rand=rd.nextInt(RecetasFre.cantidadRecetas);
						  if(rand==0)
							  rand=1;
						  
						  bundle.putInt("page",rand );
						  i.putExtras(bundle);
						  
						startActivity(i);
						break;
	
					case 2:
						
						Log.d(TAG, "[onItemClick] Comenzando FreBuscarRecetasActivity");
						i = new Intent(getApplicationContext(), FreBuscarRecetasActivity.class);
						startActivity(i);
						break;
	
					case 3:
						
						break;
	
				}

			}

		});

	}

	@Override
	public void onBackPressed() {
		Log.d(this.getLocalClassName(), "onBackPressed()");
		this.finish();
	}
}